/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.entity.report;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 *
 * @author GiangLT
 */
public class LotteryStatistic {

    private String tinhQuay;
    private String number;
    private List<Date> winDates;

    public LotteryStatistic() {
        winDates = new ArrayList<Date>();
    }

    public Date getLastWinDate() {
        if (winDates == null || winDates.isEmpty()) {
            return null;
        }
        if (winDates.size() == 1) {
            return winDates.get(0);
        }

        return Collections.max(winDates, new Comparator<Date>() {

            @Override
            public int compare(Date o1, Date o2) {
                return o1.compareTo(o2);
            }
        });
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getTinhQuay() {
        return tinhQuay;
    }

    public void setTinhQuay(String tinhQuay) {
        this.tinhQuay = tinhQuay;
    }

    public Integer getTotalWin() {
        return winDates.size();
    }

    public List<Date> getWinDates() {
        return winDates;
    }

    public void setWinDates(List<Date> winDates) {
        this.winDates = winDates;
    }

    public String getWinDatesStr() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM");
        StringBuilder sb = new StringBuilder();
        Collections.sort(winDates, new Comparator<Date>() {

            @Override
            public int compare(Date o1, Date o2) {
                return o1.compareTo(o2);
            }
        });

        for (Date date : winDates) {
            sb.append(sdf.format(date));
            sb.append(", ");
        }
        sb.deleteCharAt(sb.lastIndexOf(", "));
        return sb.toString();
    }
}
